<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <el-form
        :model="where"
        label-width="96px"
        class="ele-form-search"
        @keyup.enter.native="reload"
        @submit.native.prevent>
        <el-row :gutter="15">
          <el-col :lg="4" :md="4">

            <el-form-item label="日期:" prop="add_time">
              <el-date-picker
                type="date"
                clearable
                v-model="where.add_time"

                placeholder="请输入结束时间"/>

            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="6">
            <el-date-picker
              type="date"
              clearable
              v-model="where.end_time"

              placeholder="请输入结束时间"/>


          </el-col>
          <el-col :lg="6" :md="12">
            <div class="ele-form-actions">
              <el-button
                type="primary"
                icon="el-icon-search"
                class="ele-btn-icon"
                @click="reload">查询
              </el-button>
              <el-button @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :where="where"
        :datasource="url"
        :columns="columns"
        :selection.sync="selection"
        height="calc(100vh - 315px)">
        <!-- 表头工具栏 -->
        <template slot="toolbar">

          <el-button
            size="small"
            type="success"
            icon="el-icon-download"
            class="ele-btn-icon"
            @click="exportExcel"
            v-if="permission.includes('sys:order:export')">导出
          </el-button>
        </template>


        <!-- 1正常 0  冻结 -->

        <template slot="type" slot-scope="{row}">
          <el-tag v-if="row.type === 1" type="success" size="small">预约包厢</el-tag>

          <el-tag v-if="row.type === 2" type="danger" size="small">开通会员</el-tag>
          <el-tag v-if="row.type === 3" type="info" size="small">预约座位</el-tag>
          <el-tag v-if="row.type === 4" type="info" size="small">充值金额</el-tag>
          <el-tag v-if="row.type === 5" type="info" size="small">购买积分商品</el-tag>
          <el-tag v-if="row.type === 6" type="info" size="small">包厢订单退订</el-tag>


        </template>
        <!-- 操作列 -->
        <template slot="action" slot-scope="{row}">
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->

  </div>
</template>

<script>
import {mapGetters} from "vuex";


export default {
  name: 'ExamUsercrad',

  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表格数据接口
      url: '/profit/index',
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
        },
        {
          prop: 'nickname',
          label: '用户昵称',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        },
        {
          prop: 'mobile',
          label: '用户手机号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center',
        },
        {
          prop: 'order_price',
          label: '价格',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        },
        {
          prop: 'price',
          label: '收益金额',
          showOverflowTooltip: true,
          minWidth: 150,
          align: 'center',
        },
        {
          prop: 'type',
          label: '收益类型',
          showOverflowTooltip: true,
          minWidth: 150,
          slot: 'type',
        },
        {
          prop: 'referrer',
          label: '推荐商家名称',
          align: 'center',
          showOverflowTooltip: true,
        },
        {
          prop: 'direct_name',
          label: '一级商家名称',
          align: 'center',
          showOverflowTooltip: true,
        },
        {
          prop: 'second_name',
          label: '二级商家名称',
          align: 'center',

          showOverflowTooltip: true,

        },


      ],
      // 表格搜索条件
      where: {},
      // 表格选中数据
      selection: [],
      typeList: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      showEdits: false,
    };
  },

  methods: {
    /* 刷新表格 */
    reload() {
      this.$refs.table.reload({where: this.where});
    },
    /* 重置搜索 */
    reset() {
      this.where = {};
      this.reload();
    },
    /* 显示编辑 */
    openEdit(row) {

      this.current = row;
      this.showEdit = true;
    },

    /* 显示编辑 */
    openEdits(row) {

      this.current = row;
      this.showEdits = true;
    },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/order/delete', {id: row.order_id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    endorder(row) {
      const loading = this.$loading({lock: true});
      this.$http.post('/order/endorder', {id: row.order_id}).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
          this.reload();
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的用户期限卡吗?', '提示', {
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({lock: true});
        this.$http.post('/cradorder/delete', {id: this.selection.map(d => d.id)}).then(res => {
          loading.close();
          if (res.data.code === 0) {
            this.$message.success(res.data.msg);
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch(e => {
          loading.close();
          this.$message.error(e.message);
        });
      }).catch(() => {
      });
    },


    /* 更改1正常 0  冻结 3 */
    status(row) {
      const loading = this.$loading({lock: true});
      let params = Object.assign({
        "id": row.id,
        "status": row.status
      })
      this.$http.post('/cradorder/status', params).then(res => {
        loading.close();
        if (res.data.code === 0) {
          this.$message.success(res.data.msg);
        } else {
          row.status = !row.status ? 1 : 2;
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        loading.close();
        this.$message.error(e.message);
      });
    },
  }
}
</script>

<style scoped>
</style>
